package com.sgb.link.api;

import android.text.TextUtils;

import com.swgk.core.util.SharedPreferenceUtil;

import org.jetbrains.annotations.NotNull;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * @author: 杨畔
 * @date: 4/13/21 4:50 PM
 * @Description: 验证内容拦截器
 */
public class CookieInterceptor implements Interceptor {
    @Override
    public @NotNull Response intercept(Chain chain) throws IOException {
        String token = SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LOGIN_TOKEN, "");
        Request request = chain.request();
        //设置header信息
        Request.Builder builder = request.newBuilder();
        if (!TextUtils.isEmpty(token)) {
            builder.addHeader("Authorization", "Bearer " + token);
        } else {
            //登录接口临时使用
           // builder.addHeader("Authorization", "");
        }
        Request build = builder.build();
        return chain.proceed(build);
    }
}
